/*
 * Copyright 2008 Neil Bacon
 * Distributed under the terms of the Mozilla Public License version 1.1
 * or the GNU General Public License version 3.
 */

package nb.xadd.node.impl;

import nb.xadd.node.Node;
import nb.xadd.operator.BinaryOperator;

public class RealEqualDecisionNode extends AbstractRealDecisionNode {

    private final int hashCode;

    protected RealEqualDecisionNode(int realVarIndex, double testValue, Node trueChild, Node falseChild) {
        super(realVarIndex, testValue, trueChild, falseChild);
        hashCode = 37 * super.calcHashCode();
    }

    @Override
    public Ordering getOrdering() {
        return Ordering.REAL_EQUAL;
    }

    //	@Override
    //	public boolean isTrue(DataModel model) {
    //		return model.getReal(getRealVarIndex()) == getTestValue();
    //	}
    //	
    @Override
    public int hashCode() {
        return hashCode;
    }

    @Override
    String getSymbol() {
        return " == ";
    }

    @Override
    public Node apply(BinaryOperator binaryOperator, Node node) {
        return node.applyRealEqualDecision(binaryOperator, this);
    }

    @Override
    public Node applyConstantValue(BinaryOperator binaryOperator, ConstantValueNode node) {
        return binaryOperator.executeConstantRealEqualDecision(node, this);
    }

    @Override
    public Node applyLinearValue(BinaryOperator binaryOperator, LinearValueNode node) {
        return binaryOperator.executeLinearRealEqualDecision(node, this);
    }

    @Override
    public Node applyPolynomialValue(BinaryOperator binaryOperator, PolynomialValueNode node) {
        return binaryOperator.executePolynomialRealEqualDecision(node, this);
    }

    @Override
    public Node applyBooleanDecision(BinaryOperator binaryOperator, BooleanDecisionNode node) {
        return binaryOperator.executeBooleanDecisionRealEqualDecision(node, this);
    }

    @Override
    public Node applyRealEqualDecision(BinaryOperator binaryOperator, RealEqualDecisionNode node) {
        return binaryOperator.executeRealEqualDecisionRealEqualDecision(node, this);
    }

    @Override
    public Node applyRealGreaterOrEqualDecision(BinaryOperator binaryOperator, RealGreaterOrEqualDecisionNode node) {
        return binaryOperator.executeRealEqualDecisionRealGreaterOrEqualDecision(this, node);
    }
}
